function! health#check_python3() abort
    let g:python3_candidates = get(g:, 'python3_candidates', [
                \ 'C:\Programs\Python\3.10.32\python.exe',
                \ 'C:\Programs\Python\python-3.6.8rc1-embed-win32\python.exe',
                \ 'C:\Programs\Python\3.6\python.exe'
                \ ])
    for python3_executable_path in g:python3_candidates
        if !has('python3')
            " echom "setup_python3(" . python3_executable_path . ")"
            let g:python3_enabled = health#setup_python3(python3_executable_path)
        else
            let g:python3_enabled = v:true
        endif
    endfor
    return g:python3_enabled
endfunction

function! health#python3_name() abort
    if has('win32')
        return 'python.exe'
    else
        return 'python'
    endif
endfunction

function! health#python3_dllname() abort
    if !exists('g:python3_dllname')
        set pythonthreedll&
        let g:python3_dllname = &pythonthreedll
    endif
    return g:python3_dllname
endfunction

function! health#setup_python3(python3_candidate) abort
    let python_home_path = fnamemodify(a:python3_candidate, ':p:h')
    let g:python3_host_prog = globpath(python_home_path, health#python3_name())
    if filereadable(g:python3_host_prog)
        if !executable(g:python3_host_prog)
            echoerr "python3_host_prog = " . g:python3_host_prog . " is not executable?"
            return v:false
        else
            let g:python3_home = substitute(fnamemodify(g:python3_host_prog, ':p:h'), '\', '\\', 'g')
            if isdirectory(g:python3_home)
                let &pythonthreehome = g:python3_home
                " echom "python3_home = " . &pythonthreehome 
            else
                echoerr "python3_home = " . &pythonthreehome . " is not a directory?" 
                return v:false
            endif
            let g:python3_dll = fnamemodify(globpath(g:python3_home, health#python3_dllname()), ':p')
            if filereadable(g:python3_dll)
                let &pythonthreedll = g:python3_dll
                " echom "python3_dll = " . &pythonthreedll
            else
                echoerr "python3_dll = " . g:python3_dll . " is not readable?" 
                return v:false
            endif
        endif
    endif
endfunction

